<%--
  Created by IntelliJ IDEA.
--%>
<%@ page language="java" pageEncoding="utf-8" %>

<html>

<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/public/mapObj.js"></script>
<head>
    <title>场库停车场管理</title>
</head>

<style>

    .BMapLib_bubble_title a{
        color: #3d6dcc;
        text-decoration: none;
        font-size: 12px;
        font-weight: 400;
        margin-left: 10px;
        outline: 0;
        cursor: pointer;
    }
    #result li{
         list-style-type: none;
        margin-left:3px;
        margin-top:-17px;
        border-bottom-width: 1px;
        border-bottom-style: dashed;
        border-bottom-color: rgb(219, 219, 219);
        cursor: pointer;
    }
    #result li:hover{background:#EEEEEE; }

</style>


<body style="overflow: hidden;">
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>
    场库管理 <span class="c-gray en">&gt;</span>
    停车信息列表
</nav>
<div class="container">
    <div id="right" style='float:right;width:80%;height:99%;border-left:2px ridge;overflow: hidden'>

        <div class="righthead">
            <div style="height:9px"></div>
            <div id="showBtn" class="hideLeft"></div>
            <div class="hideLeftT">
                <div id="refresh" class="hideLeftTwo"></div>
                <div id="text" class="refreshtext"><span>刷新</span></div>
            </div>
        </div>
        <div id="fieldMapObj" style="width:99%;height:99%">
        </div>

    </div>
    <div id="left" style='width:20%;height:99%;'>
        <div id="param" class="lefthead">

            &nbsp;
            <input type="text" placeholder=" 停车场名称" style="width:150px;height:27px;padding-left:5px;margin-top: 5px" class="input-text"
                   id="name">&nbsp;
            <input class="btn btn-primary size-S radius"  style="margin-top: 5px" type="button" id="doSearch" value="搜索">

            <div  style=" margin-left: 10px; margin-top: 4px" >
                <input type="radio" name="radio" value="company"
                       id="company"  checked="checked">
                <label for="company" >名称</label>
                <input type="radio" name="radio"  value="parkaddress" id="parkaddress">
                <label for="parkaddress" >地址</label>
                &nbsp;

                <label for="totalparknum"  >车位数>=</label>
                <input type="text"  name="number" id="totalparknum" style="width: 30px;height: 20px"
                       value="0">
            </div>


        </div>
        <div id="result" class="parkinfos"></div>
        <div id="resulttotal" style="font-size: 12px;color: #999;height: 42px;line-height: 42px;">系统为您找到相关结果${total}个</div>
        <div id="pagination" class="pagination" style="text-align:center;margin-top:5px"><!-- 这里显示分页 --></div>
    </div>
</div>


</body>
</html>
<%@include file="../../head-ui.jsp" %>
<script type="text/javascript">
    var map = new BMap.Map("fieldMapObj");    // 创建Map实例
    var listMapInfo=null;
    var index;
    $(function () {
        var total = parseInt('${total}');
        initPagination(total/16);

        //地图
        var poi = new BMap.Point(121.389257, 31.216542);
        map.centerAndZoom(poi, 14);
        map.addControl(new BMap.MapTypeControl());   //添加地图类型控件
        map.setCurrentCity("上海");          // 设置地图显示的城市 此项是必须设置的
        map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放

//刷新
        $('#text').click(function () {

            if (pattern($('#totalparknum').val())) {
                map.clearOverlays();
                search(index, 10, $("#name").val());
            }else{
                RefresErrorDialog();
            }
        });

        //搜索
        $("#doSearch").click(function () {
            var para=$("#name").val();
            if (pattern($('#totalparknum').val())) {
                $.ajax({
                    url: '<%=request.getContextPath()%>/back/fieldpark/gettotal.do',
                    type: 'POST',
                    data: "company=" + (para) +
                    "&columnname=" + pd()["radio"] + "&numcondition=" + (pd()["totalparknum"] || ""),
                    success: function (json) {
                        $("#pagination").empty()
                        var thistotal = parseInt(json.total);
                        $("#resulttotal").empty().append("系统为您找到相关结果" + thistotal + "个")
                        initPagination(thistotal / 16);
                    }
                });
            }else{
                searchErrorDialog();
            }
        });
    });

    var initPagination = function (num) {

        $("#pagination").pagination(num, {
            items_per_page:1,
            num_display_entries:4,
            num_edge_entries:2,
            callback: pageselectCallback
        });
    };
    function pageselectCallback(page_index, jq) {
        $("#result").empty().append("正在加载数据,请稍等.....");
        $(".next").hide();
        $(".prev").hide();
        var para=$("#name").val();
        search(page_index+1,16,para);
    }
    var addMarker = function(obj) {
        var point =new BMap.Point(parseFloat(obj.lng), parseFloat(obj.lat));
        var myIcon = new BMap.Icon("<%=request.getContextPath()%>/resources/images/park/park.png", new BMap.Size(25,39),{
            imageSize:new BMap.Size(20, 34)
        });
        var marker = new BMap.Marker(point,{icon:myIcon});  // 创建标注
        marker.mydata=obj;
        var labelcontent=obj.currentparkingno||"未知";
        setlabel(marker,labelcontent );
        map.addOverlay(marker);
        var p=obj;
        var infoWindow = getContent(obj);
//                                                                new BMap.InfoWindow("" +
//                                                                "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>"+ p.company+"</h4>" +
//                                                                "<p style='font-size:14px;'>地址:"+p.location+","+ p.parkaddress+"</p>" +
//                                                                "<p style='font-size:14px;'>联系人:"+ p.contactpeople+"</p>" +
//                                                                "<p style='font-size:14px;'>联系电话:"+p.mobile+"</p>");
        p.infoWindow=infoWindow;
        p.mapthis=marker;
        listMapInfo.push(p);
        marker.addEventListener("click",getMarkerClick);
        return point;
    }



    function linkMap(uuid,x,y) {
        $("#result li").css("background","");
        $("#"+uuid).css("background","#EEEEEE");
        var point =new BMap.Point(parseFloat(x), parseFloat(y));
        map.centerAndZoom(point,14);
        var win=getInfoWindow(uuid);
        if(win!=null){
            win.infoWindow.open(win.mapthis);
            //win.mapthis.openInfoWindow(win.infoWindow)
        }

    }
    function getMarkerClick(m){
        var p = m.target.mydata;       //获取marker的位置
        var infoWindow = new BMap.InfoWindow("" +
                "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>"+ p.company+"</h4>" +
                "<p style='font-size:14px;'>地址:"+p.location+","+ p.parkaddress+"</p>" +
                "<p style='font-size:14px;'>联系人:"+ p.contactpeople+"</p>" +
                "<p style='font-size:14px;'>联系电话:"+p.mobile+"</p>");

        var win=getContent(p);
        win.open(this);
  //      this.openInfoWindow(infoWindow)
  //        alert("marker的位置是" + p.lng + "," + p.lat);
    }
    function getInfoWindow(uuid){
        var result=null;
        for(var i=0;i<listMapInfo.length;i++){
            var p=listMapInfo[i];
            if(p.uuid==uuid){
                result=p;
                break;
            }
        }
        return result;
    }
    function search(curPage,pageSize,param) {
        index=curPage;

        $.ajax({
            url: '<%=request.getContextPath()%>/back/fieldpark/list.do',
            type: 'POST',
            data: "curPage=" + curPage + "&pageSize=16&company=" + param+
            "&columnname=" + pd()["radio"] + "&numcondition=" + pd()["totalparknum"] || "",
            success: function (json) {
                map.clearOverlays();//删除所有图标
                listMapInfo=new Array();
                var html = "";
                var arr = [];
                for (var i = 0; i < json.data.length; i++) {
                    var obj = json.data[i];
                    if (i == json.data.length) {

                    } else {
                        var str = "&nbsp;&nbsp;<li id='" + obj.uuid + "'"+
//                                "onmouseover=\"onmouseover_Style(\"" + obj.uuid + "\")\"" +
                                "onclick='linkMap(\"" + obj.uuid + "\"," + obj.lng + "," + obj.lat + ")'>" +
                                "" + (i + 1) + "、" + obj.parkaddress +
                                " <a onclick=\"showParkEdit('" + obj.uuid + "')\" href='#' class='xq'>详情>>" + "</a>" +
                                "</li>";
                    }
                    html += str;
                    arr.push(addMarker(obj));
                }
                $("#result").empty().append(html);
            }
        });
    }
    function getContent(p){
        var parknum=p.currentparkingno||"未知";
        var content = '<div style="margin:0;line-height:20px;padding:2px;">' +
//                '<img src="../img/baidu.jpg" alt="" style="float:right;zoom:1;overflow:hidden;width:100px;height:100px;margin-left:3px;"/>' +
                '地址：'+p.location+","+ p.parkaddress+'<br/>' +
                '联系人：'+p.contactpeople+'<br/>' +
                '联系电话：'+ p.mobile+'<br/>' +
                '停车场容量(个)：'+ p.totalparknum+'<br/>' +
                '当前停车数(个)：'+parknum+'<br/>' +
                '</div>';
        var url="<%=request.getContextPath()%>/back/fieldpark/edit_page"+ p.uuid+".do";
        var searchInfoWindow = new BMapLib.SearchInfoWindow(map, content, {
            title  : p.company+"<a class=\"iw_poi_detail\" href=\"javascript:void(0);\" " +
                    "onclick=\"showParkEdit('"+p.uuid+"')\" " +
                    ">详情»</a>",      //标题
            width  : 290,             //宽度
            height : 105,              //高度
            panel  : "panel",         //检索结果面板
            enableAutoPan : true,     //自动平移
            enableSendToPhone : false, //是否启动发送到手机功能
            searchTypes   :[
//                BMAPLIB_TAB_SEARCH,   //周边检索
//                BMAPLIB_TAB_TO_HERE,  //到这里去
//                BMAPLIB_TAB_FROM_HERE //从这里出发
            ]
        });
        return searchInfoWindow;
    }
    function showParkEdit(unid) {
        var myurl= "<%=request.getContextPath()%>/back/fieldpark/edit_page"+unid+".do";
        <%--layer_show("停车场详情",myurl);--%>
        var index = layer.open({
            type: 2,
            title: "停车场详情",
            content: myurl
        });
        layer.full(index);
    }



    function pd() {
        var xzcondition = new Object();
//        if ($('#totalparknum').is(':checked')) {
//            xzcondition["checkbox"] = $("#totalparknum").val();
//        } else {
//            xzcondition["checkbox"] = "";
//        }
        xzcondition["totalparknum"]=$('#totalparknum').val();
        if ($('#company').is(':checked')) {
            xzcondition["radio"] = $("#company").val();
        } else if ($('#parkaddress').is(':checked')) {
            xzcondition["radio"] = $("#parkaddress").val()
        }


        return xzcondition;

    }
</script>